package 第14届;

public class B_幸运数字 {
	public static void main(String[] args) {
		
		int count = 0;
		int num = 0;
		while(count != 2023) {
			num++;
			int temp = num;
			int add = 0;
			// 十进制
			while(temp != 0) {
				add += temp % 10;
				temp = temp / 10;
			}
			// 取余后不为0.说明不符合
			if(num % add != 0) {
				continue;
			}
			
			// 八进制
			int eight = Integer.parseInt(Integer.toString(num, 8));
			temp = eight;
			add = 0;
			while(temp != 0) {
				add += temp % 10;
				temp = temp / 10;
			}
			if(num % add != 0) {
				continue;
			}
			
			// 二进制
			String two = Integer.toString(num, 2);
			add = 0;
			for(int i = 0; i < two.length(); i++) {
				if(two.charAt(i) == '1') {
					add++;
				}
			}
			if(num % add != 0) {
				continue;
			}
			
			String six = Integer.toString(num, 16);
			add = 0;
			for(int i = 0; i < six.length(); i++) {
				String str = String.valueOf(six.charAt(i));
				add += Integer.parseInt(str, 16);
			}
			if(num % add != 0) {
				continue;
			}
			
			count++;
//			System.out.println("num:" + num  + "six:" + six + " count:" + count);
			// 215040
		}
		System.out.println(num);
		
		
	}
}
